package com.example.j202411.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.j202411.Model.ChatResponse;
import com.example.j202411.utils.ChatApiConstants;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ChatViewModel extends ViewModel {
    private MutableLiveData<ChatResponse> chatResponse = new MutableLiveData<>();

    public LiveData<ChatResponse> getChatResponse() {
        return chatResponse;
    }

    public void sendMessage(String message) {
        ChatApiConstants.chatService.getChatResponse(message).enqueue(new Callback<ChatResponse>() {
            @Override
            public void onResponse(Call<ChatResponse> call, Response<ChatResponse> response) {
                if (response.isSuccessful() && response.body() != null) {
                    chatResponse.setValue(response.body());
                }
            }

            @Override
            public void onFailure(Call<ChatResponse> call, Throwable t) {
                // Handle failure
            }
        });
    }
}
